import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/login"
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
    if(to.path == '/login'){//如果是登录界面就放行
      return next();
    }
    if(sessionStorage.赵志文){//如果不是登录界面，就判断是否有session的key值，有就行。
      return next();
    }

    return next({path:"/login"});//如果不是登录页，也没有session ，就强制转换到login页面去
})

export default router
